import { Injectable } from '@angular/core';
import { BaseService } from '@core/routes-services/base.service';
import { CacheService } from '@core/routes-services/cache.service';
import { HttpClient } from '@angular/common/http';

/**
 * 收益提现记录表 服务
 */
@Injectable()
export class ProfitWithdrawService extends BaseService {

  constructor(http: HttpClient, cacheService: CacheService) {
    super(http, cacheService);
  }

  base_url: any = 'api/marketCustomerWithdraw';


  /**
   * 分页
   *
   * @param user
   * @returns {Promise<any>}
   */
  pagination(page: any, keyword: any,status:any): Promise<any> {
    const url = this.base_url + '/pagination';
    if (keyword) {
      page['_filter_like_cusName'] = keyword;
    }
    if (status) {
      page['_filter_like_status'] = status;
    }
    page['_sort_by_'] = 'saveTime_desc';
    return this.post(url, page);
  }

  /**
   * 修改
   *
   * @param id
   * @param entity
   * @returns {Promise<any>}
   */
  saveOrUpdateEntity(id: any, entity: any): Promise<any> {
    if (id) {
      const url = this.base_url + '/' + id;
      return this.put(url, entity);
    } else {
      const url = this.base_url;
      return this.post(url, entity);
    }
  }

  /**
   * 获取查看详情
   *
   * @param id
   * @returns {Promise<any>}
   */
  detail(id: any): Promise<any> {
    const url = this.base_url + '/' + id;
    return this.get(url);
  }

  /**
   * 删除
   *
   * @param ids
   * @returns {Promise<any>}
   */
  deleteEntity(ids): Promise<any> {
    this.cacheService.setDistrict(null);
    const url = this.base_url + '/delete/';
    return this.delete(url, ids);
  }

  /**
   * 获取全部
   *
   * @returns {Promise<any>}
   */
  getAll(): Promise<any> {
    const url = this.base_url + '/all';
    return this.get(url);
  }


  /**
   * 审核
   * @param id         待更新id
   * @param status      状态status
   * @param type       通过时付款方式 1 线下付  2 线上付
   * @param modifyData 待更新的数据
   * @param entity
   * @returns {Promise<any>}
   */
  auditing(id: any, status: any, type: any, entity: any): Promise<any> {
    const url = this.base_url + '/auditing/' + id + '/' + status + '/type/' + type;
    return this.put(url, {auditingReason:entity.auditingReason});
  }

  reSend(id: any): Promise<any> {
    const url = this.base_url + '/actions/reSend/' + id;
    return this.put(url, {});
  }
}
